<?php
$appkey = "bdaaa723c0237db2";
$salt = md5($appkey . "_ikanfan_99496");
$checkSalt = "";
$domainList = array("ikanfan.cn","ikanfan.com","99496.com","mdb6.com"); // 这里写域名验证的域名，只写顶级域名就行了，如果是 duapp 之类的，可以写二级域名

if(isset($_SERVER['HTTP_REFERER'])){
	$referer = parse_url(strtolower($_SERVER['HTTP_REFERER']), PHP_URL_HOST);
	$ex = array_reverse(explode(".", $referer));
	$ok = false;
	foreach($domainList as $domain){
		$vex = array_reverse(explode(".", $domain));
		$ok = true;
		for($i = 0; $i < count($vex); $i++){
			if(!isset($ex[$i]) || $ex[$i] != $vex[$i]){
				$ok = false; break;
			}
		}
		if($ok){ break; }
	}
} else {
	$ok = false;
}

if((!$ok && (!isset($_REQUEST['debug']) || substr($_REQUEST['debug'], 0, 4) != substr($appkey, 0, 4))) && !empty($domainList)){
	exit("pir");
}
$type = $_REQUEST['type'];
$vid = $_REQUEST['vid'];
$playurl = $_REQUEST['url'];
if($checkSalt){
	$tm = isset($_REQUEST['tm']) ? (int)$_REQUEST['tm'] : 0;
	$check = isset($_REQUEST['check']) ? $_REQUEST['check'] : "";
	if($check != md5("{$vid}~{$tm}~{$checkSalt}")){
		exit("checksum error");
	}
}
if($type == "acku" && strlen($vid) == 24){ $type = "kuvod"; }
$m3u8 = false;
if($type == "letv" || $type == "letvcloud" || $type == "mmsid" || $type == "vmgtv" || $type == "hunantv"){ $m3u8 = true; }
$tm = time();
if(!empty($playurl)){
    $sign = md5("{$tm}~{$playurl}~{$salt}");
}else{
    $sign = md5("{$tm}~{$vid}~{$salt}");
}
$userlink = isset($_SERVER['HTTP_REFERER']) ? urlencode($_SERVER['HTTP_REFERER']) : "";
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>player</title>
<style type="text/css">body,html,div{background-color:#000;padding: 0;margin: 0;width:100%;height:100%;color:#aaa;}</style>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?9cafa9b76d4e97f2df16d84b563006f5";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>
</head>
<body>
<div id="player"></div>
<script type="text/javascript" src="/api/ck/ckplayer.js"></script>
<script type="text/javascript" src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
<?php if(preg_match("/iPad|iPhone|Android|Linux|iPod/", $_SERVER['HTTP_USER_AGENT']) && $type != "file"){ ?>
    <?php if(!empty($playurl)){ ?>
    $.getScript('/api/parse.php?h5url=<?php echo $playurl ?>&tm=<?php echo $tm ?>&sign=<?php echo $sign ?>&script=1&userlink=<?php echo $userlink ?>');
    <?php } else { ?>
	$.getScript('/api/parse.php?h5url=null&type=<?php echo $type ?>&vid=<?php echo $vid ?>&tm=<?php echo $tm ?>&sign=<?php echo $sign ?>&script=1&userlink=<?php echo $userlink ?>');
    <?php } ?>
<?php } else { ?>
    var params={bgcolor:'#FFF',allowFullScreen:true,allowScriptAccess:'always'};
<?php if($type != "file"){ ?>
<?php if(!empty($playurl)){ ?>
    var video=['/api/parse.php?h5url=<?php echo $playurl ?>&tm=<?php echo $tm ?>&sign=<?php echo $sign ?>&userlink=<?php echo $userlink ?>&ajax=1->ajax/get/utf-8'];
    var flashvars={f:'/api/parse.php?xmlurl=<?php echo $playurl ?>&tm=<?php echo $tm ?>&sign=<?php echo $sign ?>&userlink=<?php echo $userlink ?><?php echo $m3u8 ? "&m3u8=1" : ""; ?>',s:'2',c:'0',p:'1',h:'1',e:'0'};
<?php } else { ?>
    var video=['/api/parse.php?h5url=null&type=<?php echo $type ?>&vid=<?php echo $vid ?>&tm=<?php echo $tm ?>&sign=<?php echo $sign ?>&userlink=<?php echo $userlink ?>&ajax=1->ajax/get/utf-8'];
    var flashvars={f:'/api/parse.php?xmlurl=null&type=<?php echo $type ?>&vid=<?php echo $vid ?>&tm=<?php echo $tm ?>&sign=<?php echo $sign ?><?php echo $m3u8 ? "&m3u8=1" : ""; ?>&userlink=<?php echo $userlink ?>',s:'2',c:'0',p:'1',h:'1',e:'0'};
<?php } ?>
<?php } else { ?>
    var video=['<?php echo $vid ?>'];
    var flashvars={f:'<?php echo $vid ?>',s:'0',c:'0',p:'1',h:'1',e:'0'};
<?php } ?>
    CKobject.embed('/api/ck/ckplayer.swf','player','ckplayer_a1','100%','100%',false,flashvars,video,params);
<?php } ?>
	function GetQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }
	function nextxia(){
        var nextPage = GetQueryString('nextPage');
        var userlink = GetQueryString('userlink');
        if(nextPage != null && nextPage != ''){
            window.location.href = nextPage;
        }else{
            alert('最后一集了,点击确定,返回首页');
            window.location.href = userlink.split('ac')[0];
        }
    }
    function playerstop(){
        nextxia();
        return false;
    };
</script>
<div style="dislay:none;"><script src="https://s95.cnzz.com/z_stat.php?id=1261393105&web_id=1261393105" language="JavaScript"></script></div>
</body>
</html>